/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.pucp.dp1.lectura.controlador;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Ed
 */
public class MainLectura{

    /**
     * @param args the command line arguments
     */
    public MainLectura(){}
            
    public static void main(String[] args) {
        // TODO code application logic here
        VentanaDatos form= new VentanaDatos();
        form.addWindowListener(new ClassListener());        
    }

   static class ClassListener implements WindowListener{
 
        @Override
        public void windowOpened(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void windowClosing(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void windowClosed(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.            
            GestorCar gestorCar = GestorCar.getInstance();
            gestorCar.cargaArchivos();
            System.out.println("numero de carros :\t"+gestorCar.getFilelistcar().size());
            System.out.println("Espacio ocupado:\t"+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/(1024*1024)+"mb");
            /*
            System.out.println("numero de carros :\t"+gestorCar.getFilelistcar().size());
            System.out.println("Espacio ocupado:\t"+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/(1024*1024)+"mb");
            File f = new File(gestorCar.getRuta().getParent()+"\\input.txt");
            try {
                FileWriter fw = new FileWriter(f);                
                for(int i=0;i<gestorCar.getFilelistcar().size();i++)
                {
                    fw.write("placa:\t"+gestorCar.getFilelistcar().get(i).getPlaca()+
                            "\tNro Rutas:\t"+gestorCar.getFilelistcar().get(i).getRutaCar().size()+"\n");
                }
                fw.close();                
            } catch (IOException ex) {
                Logger.getLogger(MainLectura.class.getName()).log(Level.SEVERE, null, ex);
            }
            */
            gestorCar.lanzaHiloSimulador();
            //gestorCar.lanzaHiloMiron();
        }

        @Override
        public void windowIconified(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void windowActivated(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
//            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }        
    }
}
